package com.markul.android.ui.mark.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bumptech.glide.Glide
import com.markul.android.R
import com.markul.android.ui.mark.OnItemClickListener

class IconLabelAdapter(val labelList:List<Int>) :
    RecyclerView.Adapter<RecyclerView.ViewHolder>() {

        private var onLabelClick: OnItemClickListener? = null

        inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            val labelImage: ImageView = itemView.findViewById(R.id.label)
        }

        override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
            val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.item_emoji_label, parent, false)
            return ViewHolder(view)
        }

        override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
            val icon = labelList[position]
            Glide.with(holder.itemView.context).load(icon)
                .into((holder as ViewHolder).labelImage)
            holder.labelImage.setOnClickListener {
                onLabelClick?.onLabelClick(position)
            }

        }

        override fun getItemCount() = labelList.size

        fun setOnMyClickListener(
            onClickListener: OnItemClickListener?
        ) {
            onLabelClick = onClickListener
        }
}